package utils;

import net.sf.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by David on 2017/7/30 030.
 */
public class JsonOut {
    public static String common(int code, String msg, Object data){

        HashMap<String, Object> map = new HashMap<>();
        map.put("error", code);
        map.put("msg", msg);
        map.put("data", data);

        try{
            return JSONObject.fromObject(map).toString();
        }catch (Exception ex){
            return "{\"error\": 500, \"msg\" : \"\"}";
        }

    }
//
//    public static String array(int code, String msg, List data){
//        HashMap<String, Object> map = new HashMap<>();
//        map.put("error", code);
//        map.put("msg", msg);
//        map.put("data", data);
//
//        try{
//            return JSONObject.fromObject(data).toString();
//        }catch (Exception ex){
//            return "{\"error\": 500, \"msg\" : \"\"}";
//        }
//    }

    public static String error(int code, String msg){


        HashMap<String, Object> map = new HashMap<>();
        map.put("error", code);
        map.put("msg", msg);

        try{
            //String outStr = JSONObject.fromObject(jo).toString();
            //System.out.println(outStr);
            return JSONObject.fromObject(map).toString();//outStr;
        }catch (Exception ex){
            return "{\"error\": 500, \"msg\" : \"\"}";
        }

    }
}
